package cn.pluss.baselibrary.http;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.ParserConfig;

import java.io.IOException;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;

final class FastJsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private static final Feature[] EMPTY_SERIALIZER_FEATURES = new Feature[0];
    private Type mType;
    private ParserConfig config;
    private int featureValues;
    private Feature[] features;

    FastJsonResponseBodyConverter(Type type, ParserConfig config, int featureValues, Feature... features) {
        this.mType = type;
        this.config = config;
        this.featureValues = featureValues;
        this.features = features;
    }

    public T convert(ResponseBody value) throws IOException {
        T var2;
        try {
            var2 = JSON.parseObject(value.string(), this.mType, this.config, this.featureValues, this.features != null ? this.features : EMPTY_SERIALIZER_FEATURES);
        } finally {
            value.close();
        }
        return var2;
    }
}
